package com.syq.listener;

import com.rabbitmq.client.Channel;
import com.syq.constant.RabbitMQConstants;
import com.syq.model.StandardReport;
import com.syq.model.StandardSubmit;
import com.syq.service.ElkServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @ClassName: RabbitMqListener
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/8/30 8:11
 */
@Slf4j
@Component
public class RabbitMqListener {
    @Autowired
    private ElkServiceImpl elkService;

    @RabbitListener(queues = RabbitMQConstants.TOPIC_SMS_SEND_LOG)
    public void receiveLog(StandardSubmit standardSubmit, Channel channel, Message message){

        try {
            elkService.saveLog(standardSubmit);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            log.error("【搜索模块】应答失败:{}"+e.getMessage());
        }

    }

    @RabbitListener(queues = RabbitMQConstants.TOPIC_UPDATE_SMS_REPORT)
    public void receiveUpdate(StandardReport standardReport, Channel channel, Message message){

        try {
            elkService.updateLog(standardReport);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            log.error("【搜索模块】修改日志,修改日志失败:{}"+e.getMessage());
        }

    }
}
